
import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Leon
 */
public class DuckDie extends Sprite implements Runnable{

    private int CurrentFrame = 0;
    private boolean Running;

    public DuckDie(int X,int Y) throws IOException
    {
        // Tạo ảnh nguồn và set điểm neo ở giữa ảnh
        super(Image.createImage("/resource/Duck_die_sprite25.png"),25,30);
        defineReferencePixel(12, 15);
        setRefPixelPosition(X, Y);
        Running = true;
        Thread T = new Thread(this);
        T.start();
    }

    public void NextFrame()
    {
        setFrame(CurrentFrame);
        CurrentFrame ++;
        if(CurrentFrame == 6)
            Remove();
    }


    private void Remove()
    {
        // Tự hủy
       Running = false;
       GameManager.DuckDie.remove(this);
    }

    public void run() {
        while(Running)
        {
            NextFrame();
            try {
                if(CurrentFrame == 1 || CurrentFrame == 6)
                    Thread.sleep(300);
                else Thread.sleep(150);
            } catch (InterruptedException ex) {}
        }
    }

}
